home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CLASSSRC.PAK / TIMEIO.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  2KB  |  83 lines

  1. //----------------------------------------------------------------------------
  2. // Borland Class Library
  3. // Copyright (c) 1993, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   5.7  $
  6. //
  7. // TTime class IO and conversion implementation
  8. //----------------------------------------------------------------------------
  9. #include <classlib/pch.h>
  10. #include <classlib/time.h>
  11. #include <classlib/file.h>
  12. #include <services/checks.h>
  13. #include <stdio.h>
  14. #include <strstrea.h>
  15. #include <iomanip.h>
  16.  
  17. //
  18. // Static variable intialization:
  19. //
  20. int TTime::PrintDateFlag = 1;
  21.  
  22. string TTime::AsString() const
  23. {
  24.     _TCHAR buf[80];
  25.     ostrstream strtemp(buf, sizeof(buf));
  26.     strtemp << (*this) << ends;
  27.     string temp(buf);
  28.     return temp;
  29. }
  30.  
  31. #if defined(BI_NAMESPACE)
  32. namespace ClassLib {
  33. #endif
  34.  
  35. ostream _BIDSFAR & _BIDSFUNC operator << ( ostream _BIDSFAR & s, const TTime _BIDSFAR & t )
  36. {
  37.     _TCHAR buf[80];
  38.  
  39.     // We use an ostrstream to format into buf so that
  40.     // we don't affect the ostream's width setting.
  41.     //
  42.     ostrstream out( buf, sizeof(buf) );
  43.  
  44.     // First print the date if requested:
  45.     //
  46.     if(TTime::PrintDateFlag)
  47.         out << TDate(t) << " ";
  48.  
  49.     unsigned hh = t.Hour();
  50.     out << (hh <= 12 ? hh : hh-12) << ':'
  51.         << setfill('0') << setw(2) << t.Minute() << ':'
  52.         << setw(2) << t.Second() << ' ' << setfill(' ');
  53.     out << ( hh<12 ? "am" : "pm") << ends;
  54.  
  55.     // now we write out the formatted buffer, and the ostream's
  56.     // width setting will control the actual width of the field.
  57.     //
  58.     s << buf;
  59.     return s;
  60. }
  61.  
  62. #if defined(BI_NAMESPACE)
  63. }     // namespace ClassLib
  64. #endif
  65.  
  66. int TTime::PrintDate( int f )
  67. {
  68.     int temp = PrintDateFlag;
  69.     PrintDateFlag = f;
  70.     return temp;
  71. }
  72.  
  73. ostream _BIDSFAR & _BIDSFUNC operator << ( ostream _BIDSFAR & os, const TFileStatus _BIDSFAR & status )
  74. {
  75.     os << "File Status: " << status.fullName << '\n';
  76.     os << "    created: " << status.createTime << '\n';
  77.     os << "   modified: " << status.modifyTime << '\n';
  78.     os << "   accessed: " << status.accessTime << '\n';
  79.     os << "       size: " << status.size << '\n';
  80.     os << " attributes: " << (int)status.attribute << '\n';
  81.     return os;
  82. }
  83.